

/*
 * QuestionFrame.java
 *
 * Created on February 15, 2008, 11:37 AM
 */

/**
 *
 * @author  kpc1
 */

import java.util.*;
import java.io.*; 
import javax.swing.*;

public class QuestionFrame extends javax.swing.JFrame {
    
    int Score;
    int TotalQ;
    String Place;
    QuestionCollection QC;
    
    public QuestionFrame(int theScore, int TotalQuestion, QuestionCollection TheQuestionCollection) {
        Score = theScore;
        TotalQ = TotalQuestion;
        initComponents();
        
        QC = TheQuestionCollection;
   
        QuestionArea.setText(TheQuestionCollection.nextQuestion()[0]);
        AnsAreaA.setText(TheQuestionCollection.nextQuestion()[1]);
        AnsAreaB.setText(TheQuestionCollection.nextQuestion()[2]); 
        AnsAreaC.setText(TheQuestionCollection.nextQuestion()[3]);
        AnsAreaD.setText(TheQuestionCollection.nextQuestion()[4]);
        Place = TheQuestionCollection.nextQuestion()[4];
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jTextArea2 = new javax.swing.JTextArea();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTextArea6 = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        QuestionArea = new javax.swing.JTextArea();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        AnsAreaA = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        AnsAreaB = new javax.swing.JTextArea();
        jScrollPane4 = new javax.swing.JScrollPane();
        AnsAreaC = new javax.swing.JTextArea();
        jScrollPane6 = new javax.swing.JScrollPane();
        AnsAreaD = new javax.swing.JTextArea();
        AnsA = new javax.swing.JCheckBox();
        AnsB = new javax.swing.JCheckBox();
        AnsC = new javax.swing.JCheckBox();
        AnsD = new javax.swing.JCheckBox();
        Return = new javax.swing.JButton();
        Statisics = new javax.swing.JButton();
        CheckAns = new javax.swing.JButton();
        NextQ = new javax.swing.JButton();

        jTextArea2.setColumns(20);
        jTextArea2.setRows(5);
        jTextArea6.setColumns(20);
        jTextArea6.setRows(5);
        jScrollPane5.setViewportView(jTextArea6);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Study Buddy");
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Question", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14)));
        QuestionArea.setColumns(20);
        QuestionArea.setRows(5);
        jScrollPane3.setViewportView(QuestionArea);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 944, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Answer", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14)));
        AnsAreaA.setColumns(20);
        AnsAreaA.setRows(5);
        AnsAreaA.setText("asdf");
        jScrollPane1.setViewportView(AnsAreaA);

        AnsAreaB.setColumns(20);
        AnsAreaB.setRows(5);
        jScrollPane2.setViewportView(AnsAreaB);

        AnsAreaC.setColumns(20);
        AnsAreaC.setRows(5);
        jScrollPane4.setViewportView(AnsAreaC);

        AnsAreaD.setColumns(20);
        AnsAreaD.setRows(5);
        jScrollPane6.setViewportView(AnsAreaD);

        AnsA.setText("A");

        AnsB.setText("B");

        AnsC.setText("C");

        AnsD.setText("D");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(AnsA)
                            .addComponent(AnsB)
                            .addComponent(AnsC))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 913, Short.MAX_VALUE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 913, Short.MAX_VALUE)
                            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 913, Short.MAX_VALUE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(AnsD)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 913, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(AnsA))
                .addGap(26, 26, 26)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(AnsB))
                .addGap(20, 20, 20)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(AnsC)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(AnsD))
                .addContainerGap(21, Short.MAX_VALUE))
        );

        Return.setFont(new java.awt.Font("Tahoma", 1, 14));
        Return.setText("Main Menu");
        Return.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ReturnActionPerformed(evt);
            }
        });

        Statisics.setFont(new java.awt.Font("Tahoma", 1, 14));
        Statisics.setText("Statisics");

        CheckAns.setFont(new java.awt.Font("Tahoma", 1, 14));
        CheckAns.setText("Check Answer");
        CheckAns.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CheckAnsActionPerformed(evt);
            }
        });

        NextQ.setFont(new java.awt.Font("Tahoma", 1, 14));
        NextQ.setText("Next Question");
        NextQ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NextQActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(49, 49, 49)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(Return, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(51, 51, 51)
                        .addComponent(Statisics, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(CheckAns, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(55, 55, 55)
                        .addComponent(NextQ, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(16, 16, 16)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(Statisics, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(Return, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE))
                        .addContainerGap(63, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(NextQ, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(CheckAns, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void CheckAnsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CheckAnsActionPerformed
        QuestionClass QI = new QuestionClass();
        boolean state;
        
        if(AnsA.isSelected() == true){
            Choice[0] = true;
        }
        else{
            Choice[0] = false;            
        }
        
        if(AnsB.isSelected() == true){
            Choice[1] = true;
        }
        else{
            Choice[1] = false;            
        }
        
        if(AnsC.isSelected() == true){
            Choice[2] = true;
        }
        else{
            Choice[2] = false;            
        }
        
        if(AnsD.isSelected() == true){
            Choice[3] = true;
        }
        else{
            Choice[3] = false;            
        }
        
        state = QI.CheckAnswer(Choice, Place);
        if(state == true)
        {
            JOptionPane.showMessageDialog(null, "Correct");
            if(checker = true)
            {
                Score =+ 1;
                TotalQ =+ 1;
            }
        }
        
        else 
        {
            JOptionPane.showMessageDialog(null, "Incorrect");
            if(checker = true)
            {
                TotalQ =+ 1;
            }
        }
        
        checker = false;
    }//GEN-LAST:event_CheckAnsActionPerformed

    private void NextQActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NextQActionPerformed
      
        if (Qstore[0] == "~~~~~~~~~~~~~~~~~~~~")
        {
            JOptionPane.showMessageDialog(null, "No more questions are avaiable.");
        }
        
        else
        {    
            QuestionFrame nextQuestion = new QuestionFrame(Score,TotalQ ,QC);
            nextQuestion.setVisible(true);
            this.setVisible(false);
            this.dispose();
        }
        checker = true;
    }//GEN-LAST:event_NextQActionPerformed

    private void ReturnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ReturnActionPerformed
        /*BuddyLoader BL = new BuddyLoader();
        BL.setVisible(true);
        this.setVisible(false);
        dispose();
        */
}//GEN-LAST:event_ReturnActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                
                new QuestionFrame(0, 0,new QuestionClass()).setVisible(true);
            
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox AnsA;
    private javax.swing.JTextArea AnsAreaA;
    private javax.swing.JTextArea AnsAreaB;
    private javax.swing.JTextArea AnsAreaC;
    private javax.swing.JTextArea AnsAreaD;
    private javax.swing.JCheckBox AnsB;
    private javax.swing.JCheckBox AnsC;
    private javax.swing.JCheckBox AnsD;
    private javax.swing.JButton CheckAns;
    private javax.swing.JButton NextQ;
    private javax.swing.JTextArea QuestionArea;
    private javax.swing.JButton Return;
    private javax.swing.JButton Statisics;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JTextArea jTextArea6;
    // End of variables declaration//GEN-END:variables
    
    public String[] Qstore = new String[5];
    public boolean[] Choice = new boolean[4];
    public boolean checker = true;
}
